#include "Win32Exception.hpp"
#include "StringUtils.hpp"

#include <windows.h>

namespace EGlib
{
  Win32Exception::Win32Exception(DWORD error_code)
  {
    this->error_code = error_code;
  }

  Win32Exception Win32Exception::get_last_error()
  {
    return Win32Exception(GetLastError());
  }

  Glib::ustring Win32Exception::what() const
  {
    wchar_t *message;
    FormatMessage(
      FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
      NULL,
      error_code,
      0,
      (LPTSTR)&message,
      0,
      NULL);
    Glib::ustring ret = to_ustring(message);
    LocalFree(message);
    return ret;
  }
}
